// Pages/business/bussiness.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    date: '2019-01-01',
    index:0,/**+1 */
    selectorc:["金钱交易","物物交易"],
    exchangeThingId:0,
    wexin:'',
    price:'',
    thisngsId:''/**页面跳转时赋值 */
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      var that=this
    console.log(options.thingsId+"qweqwe")
      that.setData({
        thisngsId: options.thingsId/**id */
      })
  },

  inwexin:function(e){
    /*微信*/
    this.setData({
      wexin:e.detail.value
    })
  },
  inprice:function(e){
    /**价格 */
    this.setData({
      price:e.detail.value
    })
  }
  ,
  inthingid:function(e){
    /*物物id*/
    this.setData({
      exchangeThingId:e.detail.value
    })
  }
,
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  },
  bindDateChange: function (e) {/**时间 */
   console.log(e)
    this.setData({
      date: e.detail.value
    })
  },
  changbusiness:function(e){
    this.setData({
      index:e.detail.value
    })
  },
  sendForm:function(){
    var token = wx.getStorageSync('token')
    console.log(this.data.date + "" + this.data.exchangeThingId + "" + this.data.wexin + "" + this.data.price + "" +this.data.thingsId )
    console.log(this.data.index+1)
    wx.request({
      method: "POST",
      url: 'http://47.103.21.65:5645/sell/finishSell',
    
      data: {  //参数传递
       
        finishTime:this.data.date,/**时间 */
        finished:this.data.index+1,
        exchangeThingId: this.data.exchangeThingId,
        weixin: this.data.wexin,
        finishPrice:this.data.price,
        thingsId:this.data.thisngsId
      },
      header: { //设置请求头
        'content-type': 'application/x-www-form-urlencoded',// 默认值//header:{...}用啥设置啥，
          'token':token
      },

      success: function (res) {
        console.log(res);
        wx.showToast({
          title: '交易成功',
          icon:'success'
        })
        setTimeout(function(){
          wx.navigateBack({
            delta: 2
          })
        },1000)
       
      },
      fail: function (error) { //请求失败
        console.log(error);

      }
    })
  }

})